package com.xuelang.pipeline.domain.pipeline.service.imp;

import com.xuelang.pipeline.client.common.exception.BizException;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.pipeline.dto.GroupQuery;
import com.xuelang.pipeline.domain.pipeline.Group;
import com.xuelang.pipeline.domain.pipeline.repository.GroupRepository;
import com.xuelang.pipeline.domain.pipeline.service.GroupDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 流水线分组领域服务实现类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Service
public class GroupDomainServiceImpl implements GroupDomainService {

    @Autowired
    private GroupRepository groupRepository;

    @Override
    public PageRecord<Group> pageList(long currentPage, long pageSize, GroupQuery groupQuery) {
        return groupRepository.pageList(currentPage, pageSize, groupQuery);
    }

    @Override
    public List<Group> list(GroupQuery groupQuery) {
        return groupRepository.list(groupQuery);
    }

    @Override
    public List<Group> listByUuidList(List<String> uuidList) {
        return groupRepository.listByUuidList(uuidList);
    }

    @Override
    public Boolean save(Group group) {
        if(existsName(group.getUuid(), group.getName())) {
            throw new BizException("name已经存在");
        }
        return groupRepository.save(group);
    }

    @Override
    public Boolean batchSaveOrUpdate(List<Group> groupList, String creatorId, Date createTime) {
        return groupRepository.batchSaveOrUpdate(groupList, creatorId, createTime);
    }

    @Override
    public Boolean update(Group group) {
        if(existsName(group.getUuid(), group.getName())) {
            throw new BizException("name已经存在");
        }
        return groupRepository.update(group);
    }

    @Override
    public Boolean delete(String uuid) {
        return groupRepository.delete(uuid);
    }

    @Override
    public Group query(String uuid) {
        return groupRepository.query(uuid);
    }

    @Override
    public Boolean existsName(String uuid, String name) {
        return groupRepository.existsName(uuid, name);
    }
}
